<?php

namespace Biz\model\salesRebate;

use Doraemon\pockets\datebase\BaseDbModel;
use Biz\module\Classes\CouponRebate as cCouponRebate;
use Doraemon\tools\ImgUrl as toolImgUrl;
use Biz\cache\salesrebate\Coupon as cCoupon;
use Kafka\Exception;

class SalesCouponSingle extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_sales_rebate';

    const _DATABASE_ = 'biz_sales_rebate';

    const _TABLE_NAME = 'sales_coupon_single';

    //隶属类别
    const BELONG_PERSON = 1;//个人
    const BELONG_COMPANY = 2;//公司


    public static function getAllByWhere($files = '*', $where = [])
    {
        $data = self::select($files, $where);
        return $data;
    }

    public static function getOneByWhere($files = '*', $where = [])
    {
        $data = self::get($files, $where);
        return $data;
    }

    public static function createOne($coupon=[], $params = [])
    {
        $data = [
            'uid' => $params['uid'],
            'belong_type' => $params['belong_type'],
            'coupon_code' => $coupon['code'],
            'coupon_id' => $coupon['id'],
            'admin_id'=> isset($params['admin_id'])?$params['admin_id']:0
        ];

        try{
            self::insert($data);
            return $data;
        }catch(Exception $e){
            return false;
        }


    }

}